package com.uy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.uy.system.common.constant.SystemConstants;
import com.uy.system.common.utils.SessionUtils;
import com.uy.system.distribute.DistributedCacheService;
import com.uy.system.model.entity.SysRole;
import com.uy.system.mapper.SysRoleMapper;
import com.uy.system.model.vo.SysRoleVO;
import com.uy.system.service.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uy.system.utils.BeanUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 角色信息表 服务实现类
 * </p>
 *
 * @author ly
 * @since 2024-03-22
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Resource
    private DistributedCacheService distributedCacheService;

    @Override
    public SysRole getSysRoleByUserId(Long userId) {
        if (userId == null){
            return null;
        }
        return baseMapper.getSysRoleByUserId(userId);
    }

    @Override
    public List<SysRoleVO> getSysRoleList() {
        return baseMapper.getSysRoleList();
    }

    @Override
    public List<String> getRoleList(Long userId) {
        List<String> roleList = baseMapper.getRoleList(userId);
        String key = SystemConstants.SYS_USER_ROLE_KEY + userId;
        distributedCacheService.set(key, roleList, SystemConstants.CACHE_TIME, TimeUnit.SECONDS);
        return roleList;
    }
}
